﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class CourseNet : System.Web.UI.Page
{
    db_course course = new db_course();
    db_courseware cw = new db_courseware();
    public string courseName = "";
    public string courseAbout = "";
    public string courseHour = "";
    public string courseGold = "";
    public string courseID = "";
    public string updateTime = "";
    public bool isLogin = false; //是否登录
    public bool isSell = false; //是否购买

    public string strcr = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["id"] == null)
        {
            Response.Redirect("index.aspx");
        }
        db_blogroll blogroll = new db_blogroll();
        DataSet ds_blogroll = blogroll.selectBlogrollALL();
        blogrollList.DataSource = ds_blogroll.Tables[0].DefaultView;
        blogrollList.DataBind();

        db_copyright cr = new db_copyright();
        DataSet dscr = cr.selectOne();
        strcr = "Copyright &copy; " + dscr.Tables[0].Rows[0]["cryear"].ToString() + " " + dscr.Tables[0].Rows[0]["owner"].ToString() + " ALL Rights Reserved<br/><a href=\"http://www.miibeian.gov.cn\" target=\"_blank\">" + dscr.Tables[0].Rows[0]["approve"].ToString() + "</a>";

        DataSet hit = new DataSet();
        hit = course.selectCourseSellTopType("8", "2");
        hit_list.DataSource = hit.Tables[0].DefaultView;
        hit_list.DataBind();

        hit = course.selectCourseSellTop("8");
        all_hit_list.DataSource = hit.Tables[0].DefaultView;
        all_hit_list.DataBind();

        DataSet ds = new DataSet();
        courseID = Request.QueryString["id"];
        ds = course.selectCourseInfo_id(courseID);
        if (ds.Tables[0].Rows.Count == 0 || "1".Equals(ds.Tables[0].Rows[0]["status"].ToString()))
        {
            Response.Write("<script language=javascript>alert('找不到数据！');</script>");
            return;
        }
        else
        {
            string kind = ds.Tables[0].Rows[0]["coursetype"].ToString();
            if (kind.Equals("Java"))
            {
                Response.Redirect("CourseJava.aspx?id=" + courseID);
            }
            else if (kind.Equals("DataBase"))
            {
                Response.Redirect("CourseDataBase.aspx?id=" + courseID);
            }
            else if (kind.Equals("Other"))
            {
                Response.Redirect("CourseOther.aspx?id=" + courseID);
            }
            else
            {
                courseName = ds.Tables[0].Rows[0]["courseName"].ToString();
                this.Page.Title = courseName + "_" + kind + "_课程信息 - 三剑客在线教育系统";
                courseAbout = ds.Tables[0].Rows[0]["about"].ToString();
                courseHour = ds.Tables[0].Rows[0]["courseHour"].ToString();
                courseGold = ds.Tables[0].Rows[0]["gold"].ToString();
                updateTime = ds.Tables[0].Rows[0]["updateTime"].ToString();
            }
        }

        string stuid = "";
        //判断是否登录
        try
        {
            if (Session["stuId"] != null)
            {
                isLogin = true;
                stuid = Session["stuId"].ToString();
            }
            else
            {
                isLogin = false;
            }
        }
        catch
        {
            isLogin = false;
        }

        //判读是否登录
        if (isLogin)
        {
            isSell = course.CourseisSell(stuid, courseID);

            //如果购买就显示课件下载地址
            if (isSell)
            {
                ds = cw.selectCoursewareByCourse(courseID);
                coursewareList.DataSource = ds.Tables[0].DefaultView;
                coursewareList.DataBind();
            }
        }
    }
}